from PySide6.QtCore import Qt
from PySide6.QtGui import QPen
from PySide6.QtWidgets import QGraphicsWidget, QGraphicsPathItem


class 包装用容器(QGraphicsWidget):
    def __init__(self, 父项=None):
        super().__init__(父项)
        self.是否打印边框 = False  # 是否打印边框
        self.组件 = None  # 包装的组件
        self.setCacheMode(QGraphicsPathItem.NoCache)
    def paint(self, painter, option, widget=None):
        super().paint(painter, option, widget)
        if self.是否打印边框:
            # 创建并设置边框画笔
            pen = QPen(Qt.black, 2)  # 黑色边框，宽度为2像素
            painter.setPen(pen)
            # 绘制边框
            painter.drawRect(self.boundingRect())
    def 设置容器大小策略(self, 水平策略, 垂直策略):
        self.setSizePolicy(水平策略, 垂直策略)
    def 设置组件(self, 组件):
        if self.组件:
            self.组件.setParentItem(None)
        self.组件 = 组件
        self.组件.setParentItem(self)